//
//  GCMHeTongViewController.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/8/9.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMHeTongViewController.h"
#import "GCMGongZuoRiHeViewController.h"
#import "GCMHTTableViewCell.h"
#import "GCMHTModel.h"
#import "HJDatePickerView.h"

@interface GCMHeTongViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation GCMHeTongViewController{
    
    NSMutableArray *_dataSource;
    UITableView *_tableV;
    NSInteger _currentPage;
    UIButton *_timeBtn;
    NSString *_timeStr;
}
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _currentPage = 1;
    [self initData];
    [self createUI];
    [self createTableView];
    
}

-(void)downLoadData{
    
    [GCMQualityRequst postDataWithGLC:[GCMUserInfo instance].glc Success:^(id obj, NSError *err) {
        _dataSource  = obj;
        NSLog(@"%@",_dataSource);
        [_tableV reloadData];
    }];
}

-(void)createUI{

    self.view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 64, (SCREEN_WIDTH - 20)/3, 40)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"时间:";
    label.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:label];
    
     _timeBtn = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 20)/3 + 12, 64, (SCREEN_WIDTH - 20)/3*2-2, 40)];
    NSString *timestr = [NSString stringWithFormat:@"%@",[NSDate date]];
//    NSLog(@"%@",timestr);
    //[_yysjBtn1 setTitle:timestr forState:UIControlStateNormal];
    NSArray *arrayt1 = [timestr componentsSeparatedByString:@" "];
    NSArray *arrayt2 = [timestr componentsSeparatedByString:@"-"];
    _timeStr = [NSString stringWithFormat:@"%@/%@",arrayt2[0],arrayt2[1]];
    _timeBtn.backgroundColor = [UIColor whiteColor];
    [_timeBtn addTarget:self action:@selector(ontimeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_timeBtn setTitle:arrayt1[0] forState:UIControlStateNormal];
    [_timeBtn setTitleColor:[UIColor colorWithRed:0.81 green:0.81 blue:0.81 alpha:1.0] forState:UIControlStateNormal];
    [self.view addSubview:_timeBtn];
    
    [self downLoadData];
    
}

-(void)createTableView{
    
    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 104, SCREEN_WIDTH, SCREEN_HEIGHT -104)];
    _tableV.delegate = self;
    _tableV.dataSource =self;
    _tableV.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
//    _tableV.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_tableV];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMHTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[GCMHTTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell setBackgroundColor:[UIColor colorWithRed:.93 green:.93 blue:.93 alpha:1]];
//    cell.textLabel.text = [_dataSource[indexPath.row] valueForKey:@"name"];
    NSDictionary *dic = _dataSource[indexPath.row];
//    NSLog(@"--------%@",dic);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setDic:dic];
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMGongZuoRiHeViewController * gzrhVC = [[GCMGongZuoRiHeViewController alloc]init];
    gzrhVC.a_id = [_dataSource[indexPath.row] valueForKey:@"a_id"];
    gzrhVC.ht_id = [_dataSource[indexPath.row] valueForKey:@"ht_id"];
    gzrhVC.type = [_dataSource[indexPath.row] valueForKey:@"t_type"];
    gzrhVC.jiBie_id = [_dataSource[indexPath.row] valueForKey:@"id"];
    gzrhVC.data = _timeStr;
//    NSLog(@"%@%@",gzrhVC.a_id,gzrhVC.ht_id);
    [self.navigationController pushViewController:gzrhVC animated:YES ];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"工作日核";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
}


//获取时间1
-(void)ontimeBtnClick{
    
    HJDatePickerView * datePickerView = [[HJDatePickerView alloc]init];
    [datePickerView createDatePickerMode:UIDatePickerModeDate GetTime:^(NSString *time) {
        NSString *nstring = time;
        NSArray *array = [nstring componentsSeparatedByString:@" "];
        NSArray *arrayt2 = [array[0] componentsSeparatedByString:@"-"];
        _timeStr = [NSString stringWithFormat:@"%@/%@",arrayt2[0],arrayt2[1]];
        [_timeBtn setTitle:array[0] forState:UIControlStateNormal];
    }];
    //    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    //    [window addSubview:datePickerView];
    //
    //    [datePickerView setGetTimeBlock:^(NSString *time){
    //
    //        NSString *nstring = time;
    //        NSArray *array = [nstring componentsSeparatedByString:@" "];
    //        [_yysjBtn1 setTitle:array[0] forState:UIControlStateNormal];
    //    }];
    
}

-(void)initData{
    
    _dataSource = [[NSMutableArray alloc]init];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
